<?php
namespace app\admin\model;

class admin extends \app\base\model\BaseModel{
	protected $table = 'admin';
	
    //登陆
    public function getUserInfo($username){
        $rel = $this->where(array('username'=>$username))->find();
	    if($username == $rel['username']){
		   return $rel;
        }else{
	       return false;
	   }
    }
    
    //更新登陆信息
    public function setUserInfo($id){
		$data = array();
		$data['login_ip'] = get_client_ip();
		$login_time = time();
		return $this->where(array('id'=>$id))->data($data)->update();
    }
    
    //用户列表
    public function _select(){
        return $this->table('admin as A')
            ->join('{pre}website as B ON A.website_id = B.id','left')
            ->join('{pre}admin_group as C ON A.groupid = C.id','left')
            ->field('A.*,B.name as website_name,B.url,C.name as group_name')
            ->order('a.id desc')
            ->select();
        }

    //单个用户
    public function _find($condition){
        return $this->where($condition)->find();
    }

    //删除用户
    public function _delete($condition){
        return $this->where($condition)->delete();
    }  

    //编辑用户
    public function _update($data,$condition = NULL){
        if($condition){
            return $this->where($condition)->data($data)->update();
        }else{
            return $this->data($data)->insert();
        }
    }  
}